package hung.vnptthanhhoa.cookingbook;

import hung.vnptthanhhoa.adapter.CookingList;
import hung.vnptthanhhoa.util.DBCooking;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

public class Fragment_Cooking extends Fragment {

	ListView list;
	private FragmentTransaction transaction;
	private Fragment fg;
	private DBCooking dbCooking;

	// String[] monAn = { "Xem tất cả", "Món yêu thích", "Món xào", "Món trộn",
	// "Món rán", "Món kho,rim", "Món hấp,luộc", "Món canh,súp",
	// "Món nướng", "Món cơm,cháo", "Món chè", "Món tráng miệng",
	// "Món chay", "Đồ uống", "Ăn vặt" };
	// Integer[] imageId = { R.drawable.icon_all, R.drawable.icon_yeuthich,
	// R.drawable.icon_xao, R.drawable.icon_tron, R.drawable.icon_ran,
	// R.drawable.icon_kho, R.drawable.icon_hap, R.drawable.icon_canh,
	// R.drawable.icon_nuong, R.drawable.icon_chao, R.drawable.icon_che,
	// R.drawable.icon_trangmieng, R.drawable.icon_chay,
	// R.drawable.icon_douong, R.drawable.icon_anvat, };

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.fragment_tab_cooking,
				container, false);
		dbCooking = new DBCooking(getActivity());
		ArrayList<CookingList> arrayList = dbCooking.getArrayList();
		ArrayAdapter_Cooking adapter = new ArrayAdapter_Cooking(getActivity(),
				arrayList);
		list = (ListView) rootView.findViewById(R.id.list_cooking);
		list.setAdapter(adapter);

		list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ArrayAdapter_Cooking ad = (ArrayAdapter_Cooking) parent
						.getAdapter();
				transaction = getFragmentManager().beginTransaction();
				transaction.setCustomAnimations(R.anim.enter, R.anim.exit,
						R.anim.pop_enter, R.anim.pop_exit);
				fg = new Fragment_Food_List(ad.getItem(position).getId());
				transaction.replace(R.id.root_frame, fg);
				transaction.addToBackStack(null);
				transaction.commit();

			}
		});
		return rootView;
	}

}
